package com.sunl.mall.ali.mq.springboot;

import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertiesPropertySource;

import java.util.Properties;

public class PlaceholderFactory extends AbstractEnvironment {
    @Override
    protected void customizePropertySources(MutablePropertySources propertySources) {
        Properties properties = new Properties();
        properties.put("k1", "v1");
        propertySources.addLast(new PropertiesPropertySource("a", properties));
    }

    public static void main(String[] args) {
        PlaceholderFactory placeholderFactory = new PlaceholderFactory();
        System.out.println(placeholderFactory.resolvePlaceholders("This is a placeholder: ${k1}"));
        System.out.println(placeholderFactory.resolvePlaceholders("This is a placeholder: ${k2:defaultVal}"));
    }
}
